package 实验7_2;
import java.io.*;  
import java.net.Socket;    
public class Client {  
    public static void main(String[] args) {  
        try {  
            Socket socket = new Socket("localhost", 5988);  
            System.out.println("已连接到服务器");  
            // 获取输入流和输出流  
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));  
            PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);   
            // 从控制台读取三边数据
            BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));  
            System.out.print("请输入三角形的第一条边：");  
            double side1 = Double.parseDouble(consoleReader.readLine());  
            System.out.print("请输入三角形的第二条边：");  
            double side2 = Double.parseDouble(consoleReader.readLine());  
            System.out.print("请输入三角形的第三条边：");  
            double side3 = Double.parseDouble(consoleReader.readLine());  
   
            // 发送三边数据给服务器  
            writer.println(side1);  
            writer.println(side2);  
            writer.println(side3);  
            writer.flush(); // 刷新输出流，确保数据被发送  
  
            // 接收服务器返回的面积数据并打印  
            double area = Double.parseDouble(reader.readLine());  
            System.out.println("三角形的面积为：" + area);  
  
            // 关闭连接  
            socket.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}